package com.hxs.learn.common.utils;

import org.apache.commons.lang.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * @author huxinsheng
 */
public class ValueHelper {

    private static Logger logger = LoggerFactory.getLogger(ValueHelper.class);

    public static boolean paramRequiredCheck(Map<String, String> param, String... paramNames) {
        if (CollectionUtils.isEmpty(param)) {
            logger.warn("传入参数为空:{}", param);
            return false;
        }
        if (ArrayUtils.isEmpty(paramNames)) {
            return true;
        }
        for (String paramName : paramNames) {
            if (!param.containsKey(paramName)) {
                logger.warn("参数名:{},传入值空。传入参数:{}", paramName, param);
                break;
            }
            String paramValue = param.get(paramName);
            if (StringUtils.isEmpty(paramValue)) {
                logger.warn("参数名:{},传入值空。传入参数:{}", paramName, param);
                break;
            }
        }
        return true;
    }
}
